package interface_graphique;



import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.ListIterator;

import javax.imageio.ImageIO;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
 

public class Canvas  extends JPanel {
	  public BufferedImage imgPoisson;
	  public BufferedImage imgFruit;
	  public BufferedImage imgLait;
	  public BufferedImage imgVin;
	  public BufferedImage imgJuis;
	  public BufferedImage imgPoulet;
	  public BufferedImage imgViande;
	  public BufferedImage imgLegume;
	  public static JTextField e_type; 
	  public static JTextField e_name;
	  public  static JTextField e_size;
	  public static JTextField e_quantity;
	  public static JPanel date;
	  public static JTextField e_dateD;
	  public  static JTextField e_dateM;
	  public static JTextField e_dateY;
	  public static JRadioButton perrisable; 
	  public static JButton BouttonOk;
	  public static int dateOk = 0;
  
	 
 
	  public static Frigo f;
	  public static int comptAff =0;
	  
	  public Canvas(Frigo frigo) {
		  this.f=frigo;
		  try {
		    	imgFruit =	ImageIO.read(new File("fruit.png"));
		    	imgLait =	ImageIO.read(new File("lait.png"));
		    	imgVin =	ImageIO.read(new File("vin.png"));
		    	imgJuis =	ImageIO.read(new File("juisOrange.png"));
		    	imgPoulet =	ImageIO.read(new File("poulet.png"));
		    	imgViande =	ImageIO.read(new File("viande.png"));
		    	imgLegume =	ImageIO.read(new File("legume.png"));
				imgPoisson = ImageIO.read(new File("poisson.png"));
				  
			} catch (IOException e) {
				e.printStackTrace();
			}
		  
  }
  
  
  public void paintComponent(Graphics g) {
    int width = getWidth();
    int height = getHeight();
    //g.setColor(Color.black);
    int i =1;
    int j=1;
   	
    int x = 100+comptAff*100;
    for (E_Type mapKey : f.inventaire.keySet()) {
		if (f.inventaire.get(mapKey).isEmpty())
			continue;
	 	E_Type u = E_Type.Fish;
		 		
			 if(mapKey.equals(u)){
				 g.drawImage(imgFruit, x, 70, null);
				 comptAff++;
			 }
			 else if(mapKey.equals(E_Type.Drink)){
				 g.drawImage(imgJuis, x,70,null);
				 comptAff++;
			 }
			 else if(mapKey.equals(E_Type.Dairy)){
				 g.drawImage(imgLait, x,70,null);
				 comptAff++;
			 }
			 else if(mapKey.equals(E_Type.Vegetable)){
				 g.drawImage(imgLegume, x,70,null);
				 comptAff++;
			 }
			 else if(mapKey.equals(E_Type.Meat)){
				 g.drawImage(imgViande, x,70,null);
				 comptAff++;
			 }
			 

	}
   
   // g.drawImage(imgViande, 100,70,null);
   
   
  
   
  }
  
  /*
  
  
  public static   void fenetre() {
	  Frigo frigo = new Frigo();
	  
   JFrame frame = new JFrame("frigo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	frame.setContentPane(new JLabel(new ImageIcon("backF.png")));
    frame.setLayout(new BorderLayout());
    
    
    
    Can canvas = new Can(frigo);
    canvas.setOpaque(false);
    frame.getContentPane().add( canvas, BorderLayout.CENTER);
	
	
	 
	JPanel Contecrire= new JPanel();
	Contecrire.setLayout(new BoxLayout(Contecrire, BoxLayout.X_AXIS));
	Contecrire.add(Box.createRigidArea(new Dimension(122, 0)));
	
	
	
	JPanel ecrire = new JPanel();
	ecrire.setLayout(new BoxLayout(ecrire, BoxLayout.Y_AXIS));
	
	e_name = new JTextField("",1);
	e_name.setBorder(null);
	e_name.setBackground(Color.ORANGE);
	e_type = new JTextField("",1); 
	e_type.setBorder(null);
	e_type.setBackground(Color.green);
	e_size = new JTextField("",1);
	e_size.setBorder(null);
	e_size.setBackground(Color.magenta);
	e_quantity= new JTextField("",1);
	e_quantity.setBorder(null);
	e_quantity.setBackground(Color.ORANGE);
	ImageIcon img = new ImageIcon("boutton.png");
 
	BouttonOk = new JButton(img);
	BouttonOk.setBorderPainted(false); 
	perrisable = new JRadioButton("Perissable");
	  
    date = new JPanel();
 
	e_dateD= new JTextField("",3);
	e_dateM= new JTextField("",3);
	e_dateY= new JTextField("",3);
	 e_dateD.setBorder(null);
	 e_dateD.setBackground(Color.BLUE);
	 
	 e_dateM.setBorder(null);
	 e_dateM.setBackground(Color.white);
	 e_dateY.setBorder(null);
	 e_dateY.setBackground(Color.RED);
	date.add(e_dateD);
	date.add(e_dateM);
	date.add(e_dateY);
	date.setOpaque(false);
	date.setBorder(null);

	ecrire.add(Box.createRigidArea(new Dimension(170, 147)));
 
	ecrire.add(e_name);
	ecrire.add(Box.createRigidArea(new Dimension(0, 17)));
	ecrire.add(e_type);
	ecrire.add(Box.createRigidArea(new Dimension(0, 12)));
	ecrire.add(e_size);
	ecrire.add(Box.createRigidArea(new Dimension(0, 11)));
	ecrire.add(e_quantity);
	ecrire.add(Box.createRigidArea(new Dimension(0, 11)));
	
	
	ecrire.add(date);
	ecrire.add(perrisable);
	 
	ecrire.setOpaque(false);
	 
	perrisable.addActionListener(radioListener);
	BouttonOk.addActionListener(Ok);
	//frame.repaint();
	//frame.revalidate();
	
	Contecrire.setOpaque(false);
	 
	Contecrire.add(ecrire);
 
	
	
	JPanel ConteAjout= new JPanel();
	ConteAjout.setLayout(new BoxLayout(ConteAjout, BoxLayout.Y_AXIS));
	ConteAjout.setOpaque(false);
	ConteAjout.add(Contecrire);
	ConteAjout.add(Box.createRigidArea(new Dimension(0, 10)));
	
	ConteAjout.add(BouttonOk);
	
	BouttonOk.setOpaque(false);
	ConteAjout.add(Box.createRigidArea(new Dimension(0, 550)));
	//canvas.repaint();
	frame.getContentPane().add(ConteAjout, BorderLayout.WEST);

	  
	
	  //setopacity
	  
	frame.setSize(1000, 750);
	frame.setVisible(true);
	  
  }
  
  
  
	private static  ActionListener radioListener = new ActionListener(){
		public void actionPerformed(ActionEvent e) {
			if(perrisable.isSelected()){
			 
				dateOk = 1;
			}
			else{
				 
				dateOk=0;
				}
			
		 
	}
		
			 			 
	};
	
	private static  ActionListener Ok= new ActionListener(){
		public void actionPerformed(ActionEvent e) {
		
				if(dateOk==0){
				int size;
				int nb;
				Date dateActuelle = new Date();
				String S = new String();
				E_Type type = E_Type.Unreferenced;
				String nom = new String();
				
				nom=e_name.getText();
				size=Integer.parseInt(e_size.getText());
				nb=Integer.parseInt(e_quantity.getText());
				S=e_type.getText();
				
				switch (S) {
				case "Unreferenced":
					type = E_Type.Unreferenced;
					break;
				case "Dairy":
					type = E_Type.Dairy;
					break;
				case "Drink":
					type = E_Type.Drink;
					break;
				case "Meat":
					type = E_Type.Meat;
					break;
				case "Fish":
					type = E_Type.Fish;
					break;
				case "Eggs":
					type = E_Type.Eggs;
					break;
				case "Vegetable":
					type = E_Type.Vegetable;
					break;
				case "Fruit":
					type = E_Type.Fruit;
					break;
				}
				
				
				Produit p= new Produit(type,nom,size,nb,dateActuelle);
				 Action action= new Action();
				 action.AjoutSansDate(p,f.inventaire);
				 e_name.setText("");
				 e_quantity.setText("");
				 e_size.setText("");
				 e_type.setText("");
				 p.toString();
				 
				 
				}
				else{
					
					int size;
					int nb;
					Date dateActuelle = new Date();
					String S = new String();
					E_Type type = E_Type.Unreferenced;
					String nom = new String();
					
					nom=e_name.getText();
					size=Integer.parseInt(e_size.getText());
					nb=Integer.parseInt(e_quantity.getText());
					S=e_type.getText();
					Date date = new Date();
					date.setYear(Integer.parseInt(e_dateY.getText())); 
					date.setMonth(Integer.parseInt(e_dateM.getText())); 
					date.setDate(Integer.parseInt(e_dateD.getText())); 
					switch (S) {
					case "Unreferenced":
						type = E_Type.Unreferenced;
						break;
					case "Dairy":
						type = E_Type.Dairy;
						break;
					case "Drink":
						type = E_Type.Drink;
						break;
					case "Meat":
						type = E_Type.Meat;
						break;
					case "Fish":
						type = E_Type.Fish;
						break;
					case "Eggs":
						type = E_Type.Eggs;
						break;
					case "Vegetable":
						type = E_Type.Vegetable;
						break;
					case "Fruit":
						type = E_Type.Fruit;
						break;
					}
					
					
					P_Avec_Date p= new P_Avec_Date(type,nom,size,nb,date,dateActuelle);
					 Action action= new Action();
					 action.AjoutSansDate(p,f.inventaire);
					 e_name.setText("");
					 e_quantity.setText("");
					 e_size.setText("");
					 e_type.setText("");
					 e_dateD.setText("");
					 e_dateM.setText("");
					 e_dateY.setText("");
					 p.toString();
					
					
				}
			} 
	
		 
			 			 
	};*/
	
	/*public static void main(String[] args){
		
		 fenetre();
		
		
	}
  */
  
  
}